<template>
  <!-- 奖品记录 -->
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :model="form" label-width="150px" :inline="true">
        <el-row>
          <el-col :span="6">
            <el-form-item label="用户昵称">
              <el-input v-model="form.user_name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户手机号">
              <el-input v-model="form.user_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户类型">
              <el-select v-model="form.user_type" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in userTypeList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户身份">
              <el-select v-model="form.user_role" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in userRoleList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="邀请人昵称">
              <el-input v-model="form.invite_user_name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="邀请人手机号">
              <el-input v-model="form.invite_user_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖品状态">
              <el-select v-model="form.status" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in statusList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖品性质">
              <el-select v-model="form.reward_type" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in rewardTypeList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获奖类型">
              <el-select v-model="form.price_type" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in priceTypeList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="获得日期" width="236">
              <el-date-picker
                v-model="receive_time"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核销日期" width="236">
              <el-date-picker
                v-model="check_time"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <!-- :index="table_index" -->
        <el-table-column fixed type="index" label="序号" width="50" align="center" />
        <el-table-column label="ID" prop="id" width="50" align="center" />
        <el-table-column label="活动名称" prop="market_activity_name" align="center" />
        <el-table-column label="用户昵称" prop="user_name" align="center" />
        <el-table-column label="用户手机号" prop="user_phone" align="center" />
        <el-table-column label="用户类型" prop="user_type" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.user_type | userTypeFn}}</span>
          </template>
        </el-table-column>
        <el-table-column label="用户身份" prop="user_role" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.user_role | userRoleFn}}</span>
          </template>
        </el-table-column>
        <el-table-column label="邀请人昵称" prop="invite_user_name" align="center" />
        <el-table-column label="邀请人手机号" prop="invite_user_phone" align="center" />
        <el-table-column label="获得奖品" prop="price_name" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.price_name}}</span>
          </template>
        </el-table-column>
        <el-table-column label="获得时间" prop="receive_time" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.receive_time | dateFn}}</span>
          </template>
        </el-table-column>
        <el-table-column label="奖品状态" prop="status" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.status | statusFn}}</span>
          </template>
        </el-table-column>
        <el-table-column label="核销时间" prop="check_time" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.check_time | dateFn}}</span>
          </template>
        </el-table-column>
        <el-table-column label="奖品性质" prop="reward_type" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.reward_type | rewardTypeFn}}</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import commonFn from "@/utils/common";
import { priceList } from "@/api/invitationMange";
export default {
  data() {
    return {
      allInfoForm: null,
      receive_time: null,
      check_time: null,
      form: {
        page: 1,
        pagesize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0,
      tableLoading: true,
      userTypeList: [
        {
          name: "新用户",
          id: "0"
        },
        {
          name: "老用户",
          id: "1"
        }
      ], //用户类型
      userRoleList: [
        {
          name: "普通用户",
          id: "0"
        },
        {
          name: "plus用户",
          id: "1"
        },
        {
          name: "服务商",
          id: "2"
        }
      ],
      statusList: [
        {
          name: "已发放",
          id: "0"
        },
        {
          name: "已核销",
          id: "1"
        },
        {
          name: "未正常核销",
          id: "2"
        }
      ],
      rewardTypeList: [
        {
          name: "原本获得",
          id: "1"
        },
        {
          name: "分销获得",
          id: "2"
        }
      ],
      priceTypeList: [
        {
          name: "优惠券",
          id: "0"
        },
        {
          name: "金币",
          id: "1"
        },
        {
          name: "银币",
          id: "2"
        }
      ],
      userIdentity: [], //用户身份
      prizeStatus: [], //奖品状态
      prizeNature: [], //奖品性质
      awardType: [], //获奖类型
      dates: []
    };
  },
  filters: {
    userTypeFn(e) {
      switch (e) {
        case 0:
          return "新用户";
          break;
        case 1:
          return "老用户";
          break;
      }
    },
    rewardTypeFn(e) {
      switch (e) {
        case 2:
          return "分销获得";
          break;
        default:
          return "原本获得";
          break;
      }
    },
    priceTypeFn(e) {
      switch (e) {
        case 0:
          return "优惠券";
          break;
        case 1:
          return "金币";
          break;
        case 2:
          return "银币";
          break;
      }
    },
    statusFn(e) {
      switch (e) {
        case 0:
          return "已发放";
          break;
        case 1:
          return "已核销";
          break;
        case 2:
          return "未正常核销";
          break;
      }
    },
    userRoleFn(e) {
      switch (e) {
        case 0:
          return "普通用户";
          break;
        case 1:
          return "plus用户";
          break;
        case 2:
          return "服务商";
          break;
      }
    },
    // 时间戳转化
    dateFn(e) {
      if (e != 0) {
        return new Date(Number(e) * 1000).format("yyyy-MM-dd hh:mm:ss");
      } else {
        return "--";
      }
    }
  },
  created() {
    this.form.id = String(this.$route.query.id);
    this.getList(this.form);
  },
  methods: {
    getList(e) {
      const datas = e;
      priceList(datas)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData = res.data.data.data;
            this.page_totals = res.data.data.total;
            this.tableLoading = false;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
        })
        .catch(err => {
          this.errorStatus(err.msg);
        });
    },
    // 每页显示条数
    handleSizeChange(val) {
      this.form.pagesize = val;
      this.getList(this.form);
    },
    // 当前页
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // 查询
    handleSearch() {
      this.form.page = 1;
      if (this.receive_time) {
        this.form.receive_time = this.receive_time.join(" - ");
      } else {
        this.form.receive_time = null;
      }
      if (this.check_time) {
        this.form.check_time = this.check_time.join(" - ");
      } else {
        this.form.check_time = null;
      }
      this.getList(this.form);
    },
    // 导出
    handleExport() {
      // commonFn.downFile("女王卡订单导出", res);
    }
  }
};
</script>
<style scoped>
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.pagesCon {
  text-align: right;
  margin-top: 20px;
}
</style>